﻿@using FCZLM.Core.Models
@model IEnumerable<FCZLM.Core.Models.ProductMessage>
@{
    ViewData["Name"] = "产品列表页";
    var Product = ViewBag._productRepository as List<Products>;
    var Order = ViewBag._orderRepository as List<Orders>;
    Layout = null;
}
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <link href="/layui/css/layui.css" rel="stylesheet" />
</head>
<body>
    <div>
        <div class="demoTable layui-form">
            搜索名字：
            <div class="layui-inline">
                <input class="layui-input" name="Name" id="Name" autocomplete="off">
            </div>
            <div class="layui-inline">
                <select id="ProductId">
                    <option value="0">请选择产品名称</option>
                    @foreach (var item in Product)
                    {
                        <option value="@item.Id">@item.Name</option>
                    }
                </select>
            </div>
            <button class="layui-btn" data-type="reload">搜索</button>
          
        </div>
        <table id="demo" lay-filter="test"></table>
    </div>



    <script src="/layui//layui.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

    <script>
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#demo'
                , url: '/fproductmessage/index'
                , page: true//开启分页
                , method: "post"
                , height: 312
                , cols: [[
                    { field: 'id', title: 'ID', width: 80, sort: true, fixed: 'left' }
                    , { field: 'productId', title: '产品名称', width: 120 }
                    , { field: 'orderId', title: '订单Id', width: 120 }
                    , { field: 'name', title: '评论名称', width: 100 }
                    , { field: 'ask', title: '留言内容', width: 200 }
                    , { field: 'askTime', title: '留言时间', width: 120, sort: true }
                    , { field: 'phone', title: '联系方式', width: 120 }
                    , { field: 'huifu', title: '商家回复', width: 200 }
                    , {
                        title: '操作', width: 120, templet: function (d) {
                            if (d.huifu == null) {
                                return "<span><a lay-event='edit' class='layui-btn layui-btn-normal layui-btn-xs'>回复</a></span>"
                            } else if (d.huifu != null) {
                                return ""
                            }
                        }
                    }
                ]],
                initSort: {
                    field: 'id'
                    , type: 'desc'
                },
                page: true,
                limit: 100,
                id: "productmessageList"
            });
            var $ = layui.$, active = {
                reload: function () {
                    var nameinput = $("#Name");
                    var ProductCategoryIdinput = $("#ProductId");
                    //执行重载
                    table.reload('productmessageList', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: {
                            Name: nameinput.val(),
                            ProductId: ProductCategoryIdinput.val()
                        }
                    });
                }
            };
            $('.demoTable .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            table.on('tool(test)', function (obj) { // 注：test 是 table 原始标签的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

                if (layEvent === 'del') { //删除
                    layer.confirm('确定删除吗？', function (index) {
                        $.post("/fproducts/del", { id: data.id }, function (res) {
                            if (res.isSuccess) {
                                layer.msg(res.msg, function () {
                                    table.reload("productList")
                                });
                            } else {
                                layer.msg(res.msg);
                            }
                        })
                    });
                } else if (layEvent === "edit") {
                    var index = layer.open({
                        type: 2,
                        content: '/fproductmessage/edits/' + data.id,
                        area: ["500px", "600px"]
                    });
                }
            });

           
        });
    </script>
</body>
</html>